Repository navigation
More rules are missing named arguments - #7040
Conversation
|
This pull request has been marked as ready for review. |
|
//cc @SanderMuller |
SanderMuller
left a comment
There was a problem hiding this comment.
The named-argument changes work. Each of the three new test expectations fails on 2.3.x (527d373) and passes on 2cb886b. On 2cb886b the full test suite, make phpstan and phpcs on the changed files also pass.
I would not remove treatPhpDocTypesAsCertain from ImpossibleInArrayHaystackFiniteTypesRule. This rule reports haystack values that can never match the needle. In #7007, Ondřej said that the flag is there to relax that kind of report when it is false. ReplaceCountMismatchRule is a different case, because it checks argument types.
Without the flag, the output changes in two directions (level 8, bleedingEdge):
/** @param 'a'|'b' $s */
function phpDocOnlyImpossible(string $s): void
{
array_search($s, ['c'], true); // line 8
}
/** @param true $strict */
function phpDocStrict(int $i, bool $strict): void
{
array_search($i, ['1', 1, 2], $strict); // line 14
}- With
treatPhpDocTypesAsCertain: false, this PR reports line 8. 2.3.x does not, because the native type of the needle isstring. - With the default
true, this PR no longer reports line 14. 2.3.x reports it. The strict argument now always uses its native typebool, so thetruefrom the PHPDoc is lost.
The Shopware integration job is red on this PR. It is green on #7038 and #7039 from today. Shopware sets treatPhpDocTypesAsCertain: false. Two of the new errors come from this change: Value null and Value false in the haystack passed to in_array() in DefinitionValidator.php. In a small copy of that in_array() call, this PR reports both errors with the flag off, and 2.3.x does not. The third new error, random_int in ProductGenerator.php, is also reported on 2.3.x, so it does not come from this PR.
I suggest that you keep the reorderFuncArguments() part and restore the flag handling as it was. That is getType() when the flag is true and getNativeType() when it is false, for the needle, the haystack and the strict argument.
Things I checked that are fine:
array_keys(array: [...], strict: true)withoutfilter_valuereports nothing. Your test covers this.getTemplateType()with named arguments in reverse order is reported. Before this PR it was not.
Performance: I ran src/Rules (734 files, level 8, bleedingEdge, --debug, no result cache) 6 times on each side. The mean user CPU was 17.9 s on 2.3.x and 17.6 s on this PR. The wall time varied from 19 s to 36 s within one side, so I see no measurable difference.
This reverts commit 2cb886b.
thank you for the examples. I just added the tests and reverted to use the |
followup to #7028